#include "main.h"
#include "global.h"
#include <time.h>


void dpl_point(float ax, float ay, float az){
 glBegin(GL_POINTS);
  glColor3f(0, 0, 255);
  glVertex3f(ax,ay,az);
  glEnd();
}

void dpl_trace_points(){
 int i;
 for (i=0;i<SIZE;i++){
  if (myData.data[i].dec_ipv4 != 0){
   dpl_point(	myData.data[i].dec_ipv4,
		myData.data[i].src_port,
		myData.data[i].dst_port);
  }
 }
 glEndList();
}

/*
 * Fonction affichage du rectangle
*/
void dpl_rectangle(){
  glColor3f( 1,1,1 );
  glBegin( GL_LINE_LOOP ); /* face avant */
  glVertex3f( -127.0, -127.0,  127.0 );
  glVertex3f(  127.0, -127.0,  127.0 );
  glVertex3f(  127.0,  127.0,  127.0 );
  glVertex3f( -127.0,  127.0,  127.0 );
  glEnd();

  glBegin( GL_LINE_LOOP ); /* face arriere */
  glVertex3f( -127.0, -127.0,  -127.0 );
  glVertex3f(  127.0, -127.0,  -127.0 );
  glVertex3f(  127.0,  127.0,  -127.0 );
  glVertex3f( -127.0,  127.0,  -127.0 );
  glEnd();

  glBegin( GL_LINES ); /* autres aretes */
  glVertex3f( -127.0, -127.0,  127.0 );
  glVertex3f( -127.0, -127.0, -127.0 );

  glVertex3f(  127.0, -127.0,  127.0 );
  glVertex3f(  127.0, -127.0, -127.0 );

  glVertex3f(  127.0,  127.0,  127.0 );
  glVertex3f(  127.0,  127.0, -127.0 );

  glVertex3f( -127.0,  127.0,  127.0 );
  glVertex3f( -127.0,  127.0, -127.0 );
  glEnd();
}

/* Affichage de la scene */
void display()
{
  glClear( GL_COLOR_BUFFER_BIT );
  /* Initialiser les transformations geometriques */
  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();

  /* Repere de la camera ici */
  gluLookAt(0.0f, 0.0f, 400.0f, // position oeil
   0.0f,0.0f,1.0f, // point regardé
   0.0f,1.0f,0.0f); // vecteur haut

  /* Placer la scene par rapport a la camera */
  glTranslatef( tb_translation[0], tb_translation[1], tb_translation[2] );
  glMultMatrixf( tb_rotation );
  
  glNewList(1,GL_COMPILE); 	// Nouvelle liste d'objets

  glBegin( GL_LINES );
  glColor3f( 1,0,0 );
  glVertex3f( -350,0,0 );
  glVertex3f( -300,0,0 );

  glColor3f( 0,1,0 );
  glVertex3f( -300,0,0 );
  glVertex3f( -300,50,0 );

  glColor3f( 0,0,1 );
  glVertex3f( -300,0,0 );
  glVertex3f( -300,0,50 );
  glEnd();

  glColor4f(0, 0, 1, 1);
  glPointSize (1.0);

	
  /* Placer un objet */
  glTranslatef( 0, 0, 0 );
  glRotatef( 0, 0,1,0 );
  //glScalef( 1, 0.5, 0.25 ); 

  dpl_rectangle();		// Affichage rectangle
  dpl_point(0,0.5,0.5);		// Affichage d'un point

  glEndList();
  glCallList(1);
  dpl_trace_points();
  glCallList(2);
  glPushMatrix();

  /* Afficher le buffer */
  glutSwapBuffers();
  //glutPostRedisplay();
}
